package com.songlanyun.common.enums;

import com.baomidou.mybatisplus.annotation.EnumValue;
import com.fasterxml.jackson.annotation.JsonCreator;
import com.fasterxml.jackson.annotation.JsonFormat;
import com.fasterxml.jackson.annotation.JsonValue;
import com.songlanyun.common.drive.IntegerEnum;

import java.util.Objects;

/**
 * 微信
 */
public class WxConstant {


    /**
     * 微信消息模板类型
     * 0：售后消息
     * 1:物流通知
     */
    @JsonFormat(shape = JsonFormat.Shape.OBJECT)
    public static enum WxType implements IntegerEnum<Integer> {

        /**
         * 状态
         * 订单编号
         * 售后类型
         * 订单金额
         */
        AFTER_THE_NEWS(0, "售后消息"),

        /**
         * 订单号
         * 商品名称
         * 物流名称
         * 物流单号
         * 状态
         */
        LOGISTICS_INFORM(1, "物流通知"),

        ;

        @EnumValue
        @JsonValue
        private Integer code;

        private String msg;

        WxType(Integer code, String msg) {
            this.code = code;
            this.msg = msg;
        }

        public void setCode(Integer code) {
            this.code = code;
        }

        public String getMsg() {
            return msg;
        }

        public void setMsg(String msg) {
            this.msg = msg;
        }

        @Override
        public Integer getCode() {
            return code;
        }

        @JsonCreator
        public static WxType getByCode(int code) {
            for (WxType value : WxType.values()) {
                if (Objects.equals(code, value.getCode())) {
                    return value;
                }
            }
            return null;
        }
    }

}
